package cj.web.admin.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.admin.domain.Member;

/**
 * 
 * @author 
 *
 */
@DAO
public interface MemberDAO{
	
	@SQL("SELECT * FROM Member WHERE deleteFlag=1 AND companyGroup in (:companyGroups) "
			+ "#if(:t.code!=null ){AND code LIKE '%##(:t.code)%'} "
			+ "#if(:t.type!=null ){AND type LIKE '%##(:t.type)%'} "
			+ "#if(:t.sex!=null ){AND sex LIKE '%##(:t.sex)%'} "
			+ "#if(:t.nation!=null ){AND nation LIKE '%##(:t.nation)%'} "
			+ "#if(:t.political!=null ){AND political LIKE '%##(:t.political)%'} "
			+ "#if(:t.ageBegin!=null ){AND age >= :t.ageBegin  } "
			+ "#if(:t.ageEnd!=null ){AND age <=:t.ageEnd } "
			+ "#if(:t.education!=null ){AND education LIKE '%##(:t.education)%'} "
			+ "#if(:t.degree!=null ){AND degree LIKE '%##(:t.degree)%'} "
			+ "#if(:t.zwdj!=null ){AND zwdj LIKE '%##(:t.zwdj)%'} "
			+ "#if(:t.zyjszcmc!=null ){AND zyjszcmc LIKE '%##(:t.zyjszcmc)%'} "
			+ "#if(:t.gwlb!=null ){AND gwlb LIKE '%##(:t.gwlb)%'} "
			+ "#if(:t.zwdj!=null ){AND zwdj LIKE '%##(:t.zwdj)%'} "
			+ "#if(:t.grjsdjmc!=null ){AND grjsdjmc LIKE '%##(:t.grjsdjmc)%'} "
			+ "#if(:t.sfygxzbdw!=null ){AND sfygxzbdw LIKE '%##(:t.sfygxzbdw)%'} "
			+ "ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<Member> query(@SQLParam("t") Member member, @SQLParam("companyGroups") List<String> companyGroup);
	
	@SQL("SELECT count(1) FROM Member WHERE deleteFlag=1 AND companyGroup in (:companyGroups) "
			+ "#if(:t.code!=null ){AND code LIKE '%##(:t.code)%'} "
			+ "#if(:t.type!=null ){AND type LIKE '%##(:t.type)%'} "
			+ "#if(:t.sex!=null ){AND sex LIKE '%##(:t.sex)%'} "
			+ "#if(:t.nation!=null ){AND nation LIKE '%##(:t.nation)%'} "
			+ "#if(:t.political!=null ){AND political LIKE '%##(:t.political)%'} "
			+ "#if(:t.ageBegin!=null ){AND age >= :t.ageBegin  } "
			+ "#if(:t.ageEnd!=null ){AND age <=:t.ageEnd } "
			+ "#if(:t.education!=null ){AND education LIKE '%##(:t.education)%'} "
			+ "#if(:t.degree!=null ){AND degree LIKE '%##(:t.degree)%'} "
			+ "#if(:t.zwdj!=null ){AND zwdj LIKE '%##(:t.zwdj)%'} "
			+ "#if(:t.zyjszcmc!=null ){AND zyjszcmc LIKE '%##(:t.zyjszcmc)%'} "
			+ "#if(:t.gwlb!=null ){AND gwlb LIKE '%##(:t.gwlb)%'} "
			+ "#if(:t.zwdj!=null ){AND zwdj LIKE '%##(:t.zwdj)%'} "
			+ "#if(:t.grjsdjmc!=null ){AND grjsdjmc LIKE '%##(:t.grjsdjmc)%'} "
			+ "#if(:t.sfygxzbdw!=null ){AND sfygxzbdw LIKE '%##(:t.sfygxzbdw)%'} ")
    int querySize(@SQLParam("t") Member member, @SQLParam("companyGroups") List<String> companyGroup);
    
    @SQL("SELECT * FROM Member WHERE id=:1")
    Member queryById(int id);
    
    @SQL("SELECT * FROM Member WHERE code=:1")
    Member queryByCode(String code);
    
    @SQL("INSERT INTO Member ("
	        		+ "code,"
	        		+ "name,"
	        		+ "photo,"
	        		+ "companyGroup,"
	        		+ "department,"
	        		+ "sex,"
	        		+ "nation,"
	        		+ "political,"
	        		+ "cjdpsj,"
	        		+ "birthday,"
	        		+ "age,"
	        		+ "identityCard,"
	        		+ "cjgzsj,"
	        		+ "jrgzsj,"
	        		+ "type,"
	        		+ "gwlb,"
	        		+ "xcsgw,"
	        		+ "education,"
	        		+ "degree,"
	        		+ "bysj,"
	        		+ "byxx,"
	        		+ "sxzy,"
	        		+ "zyzwmc,"
	        		+ "zwdj,"
	        		+ "zyjszcmc,"
	        		+ "zyjszcdj,"
	        		+ "grjsdjmc,"
	        		+ "yhjn,"
	        		+ "sczj,"
	        		+ "sfygxzbdw,"
	        		+ "email,"
	        		+ "tel,"
	        		+ "address,"
	        		+ "postCode,"
	        		+ "state,"
	        		+ "deleteFlag,"
	        		+ "createUser,"
	        		+ "createAt,"
	        		+ "updateUser,"
	        		+ "updateAt"
					+") VALUES ("
					+ ":t.code,"
					+ ":t.name,"
					+ ":t.photo,"
					+ ":t.companyGroup,"
					+ ":t.department,"
					+ ":t.sex,"
					+ ":t.nation,"
					+ ":t.political,"
					+ ":t.cjdpsj,"
					+ ":t.birthday,"
					+ ":t.age,"
					+ ":t.identityCard,"
					+ ":t.cjgzsj,"
					+ ":t.jrgzsj,"
					+ ":t.type,"
					+ ":t.gwlb,"
					+ ":t.xcsgw,"
					+ ":t.education,"
					+ ":t.degree,"
					+ ":t.bysj,"
					+ ":t.byxx,"
					+ ":t.sxzy,"
					+ ":t.zyzwmc,"
					+ ":t.zwdj,"
					+ ":t.zyjszcmc,"
					+ ":t.zyjszcdj,"
					+ ":t.grjsdjmc,"
					+ ":t.yhjn,"
					+ ":t.sczj,"
					+ ":t.sfygxzbdw,"
					+ ":t.email,"
					+ ":t.tel,"
					+ ":t.address,"
					+ ":t.postCode,"
					+ ":t.state,"
					+ "1,"
					+ ":t.createUser,"
					+ "now(),"
					+ ":t.updateUser,"
					+ "now())")
    void create(@SQLParam("t") Member member);
	
	@SQL("UPDATE Member SET "
	    		+ "code=:t.code,"
		        + "name=:t.name,"
		        + "photo=:t.photo,"
		        + "companyGroup=:t.companyGroup,"
		        + "department=:t.department,"
		        + "sex=:t.sex,"
		        + "nation=:t.nation,"
		        + "political=:t.political,"
		        + "cjdpsj=:t.cjdpsj,"
		        + "birthday=:t.birthday,"
		        + "age=:t.age,"
		        + "identityCard=:t.identityCard,"
		        + "cjgzsj=:t.cjgzsj,"
		        + "jrgzsj=:t.jrgzsj,"
		        + "type=:t.type,"
		        + "gwlb=:t.gwlb,"
		        + "xcsgw=:t.xcsgw,"
		        + "education=:t.education,"
		        + "degree=:t.degree,"
		        + "bysj=:t.bysj,"
		        + "byxx=:t.byxx,"
		        + "sxzy=:t.sxzy,"
		        + "zyzwmc=:t.zyzwmc,"
		        + "zwdj=:t.zwdj,"
		        + "zyjszcmc=:t.zyjszcmc,"
		        + "zyjszcdj=:t.zyjszcdj,"
		        + "grjsdjmc=:t.grjsdjmc,"
		        + "yhjn=:t.yhjn,"
		        + "sczj=:t.sczj,"
		        + "sfygxzbdw=:t.sfygxzbdw,"
		        + "email=:t.email,"
		        + "tel=:t.tel,"
		        + "address=:t.address,"
		        + "postCode=:t.postCode,"
		        + "updateUser=:t.updateUser,"
		        + "updateAt=now()"
				+ " WHERE id=:t.id")
    void update(@SQLParam("t") Member member);
    
    @SQL("UPDATE Member SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}